package cn.broadmax.boot.modules.sys.bean;

import cn.broadmax.boot.modules.sys.entity.SysRole;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import jexx.util.StringUtil;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

@Data
@ApiModel("角色分页查询请求")
public class SysRoleSearch {

    @ApiModelProperty("角色名称")
    private String roleName;

    @ApiModelProperty("创建时间开始,yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date startCreateTime;

    @ApiModelProperty("创建时间截止,yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endCreateTime;

    public static LambdaQueryWrapper<SysRole> createWrap(SysRoleSearch search){
        LambdaQueryWrapper<SysRole> wrapper = new LambdaQueryWrapper<>();
        if(StringUtil.isNotEmpty(search.getRoleName())){
            wrapper.like(SysRole::getName, search.getRoleName());
        }
        if(search.getStartCreateTime() != null && search.getEndCreateTime() != null){
            wrapper.between(SysRole::getCreateTime, search.getStartCreateTime(), search.getEndCreateTime());
        }
        else if(search.getStartCreateTime() != null){
            wrapper.ge(SysRole::getCreateTime, search.getStartCreateTime());
        }
        else if(search.getEndCreateTime() != null){
            wrapper.le(SysRole::getCreateTime, search.getEndCreateTime());
        }
        return wrapper;
    }

}
